package com.lxl.demo01.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lxl.demo01.domain.DayDTO;
import com.lxl.demo01.domain.DoAlert;
import com.lxl.demo01.domain.MonthDTO;
import com.lxl.demo01.domain.WeekDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * DAO层快速开发（基于MP）
 */
@Mapper  // 表示该接口类的实现类对象交给mybatis底层创建，然后交由Spring框架管理。
// BaseMapper是MyBatis-Plus提供的模板mapper，其中包含了基本的CRUD方法，泛型为操作的实体类型
public interface DoAlertMapper extends BaseMapper<DoAlert> {
    // 不用一个个手写基本的crud了。

    // 自定义方法，按天、周、月查询
//    @Select("select date_format(create_time, '%Y-%m-%d') as date, count(*) as day_count, date_format(create_time,'%Y-%m-%d') as create_time " +
//            "from do_alert " +
//            "group by date order by create_time desc")
    List<DayDTO> selectDay();

    //    @Select("select date_format(create_time, '%Y-%m') as month, count(*) as month_count, date_format(create_time,'%Y-%m') as create_time " +
//            "from do_alert " +
//            "group by month order by create_time desc")
    List<MonthDTO> selectMonth();

    //    @Select("select date_format(create_time,'%Y-%u') as weeks, count(*) as week_count, date_format(create_time,'%Y-%u') as create_time " +
//            "from do_alert " +
//            "group by weeks order by create_time desc")
    List<WeekDTO> selectWeek();

    // 分页查询统计
//    @Select("select date_format(create_time, '%Y-%m-%d') as date, count(*) as day_count, date_format(create_time,'%Y-%m-%d') as create_time " +
//            "from do_alert " +
//            "where monitor_type=#{monitor_type} " +
//            "group by date order by create_time desc limit #{currentPage},#{pageSize}")
    List<DayDTO> selectDayPage(@Param("monitor_type") Integer monitor_type, @Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    //    @Select("select date_format(create_time, '%Y-%m') as month, count(*) as month_count, date_format(create_time,'%Y-%m') as create_time " +
//            "from do_alert " +
//            "where monitor_type=#{monitor_type} " +
//            "group by month order by create_time desc limit #{currentPage},#{pageSize}")
    List<MonthDTO> selectMonthPage(@Param("monitor_type") Integer monitor_type, @Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    //    @Select("select date_format(create_time,'%Y-%u') as weeks, count(*) as week_count, date_format(create_time,'%Y-%u') as create_time " +
//            "from do_alert " +
//            "where monitor_type=#{monitor_type} " +
//            "group by weeks order by create_time desc limit #{currentPage},#{pageSize}")
    List<WeekDTO> selectWeekPage(@Param("monitor_type") Integer monitor_type, @Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);
}
